<html>
<head><meta charset="utf-8"><title>how can I use libsyntax by my self · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20can.20I.20use.20libsyntax.20by.20my.20self.html">how can I use libsyntax by my self</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182927540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20can%20I%20use%20libsyntax%20by%20my%20self/near/182927540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Derek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20can.20I.20use.20libsyntax.20by.20my.20self.html#182927540">(Dec 09 2019 at 06:22)</a>:</h4>
<p>Hi is there a way to use libsyntax by my self? I want parse some source code and get some extra information,  something similar to this post. <br>
<a href="https://stackoverflow.com/questions/26575443/how-do-i-use-the-rust-parser-libsyntax-myself" target="_blank" title="https://stackoverflow.com/questions/26575443/how-do-i-use-the-rust-parser-libsyntax-myself">https://stackoverflow.com/questions/26575443/how-do-i-use-the-rust-parser-libsyntax-myself</a><br>
I added following to my Cargo.toml, and Call some API from rustc_lexer and libsyntax by my self,  rustc_lexer works fine, <br>
but after I add syntax, during build, I got lots of error. <br>
[dependencies]<br>
rustc_lexer = { path = "/home/derek/Documents/rust/rust/src/librustc_lexer" }<br>
syntax = { path = "/home/derek/Documents/rust/rust/src/libsyntax" }</p>
<p>error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a> via <code>Cargo.toml</code> instead?<br>
  --&gt; /home/derek/Documents/rust/rust/src/librustc_data_structures/lib.rs:35:1<br>
   |<br>
35 | extern crate libc;<br>
   | ^^^^^^^^^^^^^^^^^^<br>
   |<br>
   = note: for more information, see <a href="https://github.com/rust-lang/rust/issues/27812" target="_blank" title="https://github.com/rust-lang/rust/issues/27812">https://github.com/rust-lang/rust/issues/27812</a><br>
   = help: add <code>#![feature(rustc_private)]</code> to the crate attributes to enable</p>
<p>it says "add <code>#![feature(rustc_private)]</code> to the crate attributes to enable", but there are too many errors like this, I don't want to do it manually for each file.  <br>
Is there a better way to do this, Thanks!</p>



<a name="182936820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20can%20I%20use%20libsyntax%20by%20my%20self/near/182936820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20can.20I.20use.20libsyntax.20by.20my.20self.html#182936820">(Dec 09 2019 at 09:22)</a>:</h4>
<p>You can use <code>rustc-ap-syntax</code> on <a href="http://crates.io" target="_blank" title="http://crates.io">crates.io</a>, i guess?</p>



<a name="182943423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20can%20I%20use%20libsyntax%20by%20my%20self/near/182943423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20can.20I.20use.20libsyntax.20by.20my.20self.html#182943423">(Dec 09 2019 at 10:42)</a>:</h4>
<p>I suggest you instead use <code>syn</code>, which has a much more accessible API and will not break your code very two weeks ;)</p>



<a name="183026712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/how%20can%20I%20use%20libsyntax%20by%20my%20self/near/183026712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Derek <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/how.20can.20I.20use.20libsyntax.20by.20my.20self.html#183026712">(Dec 10 2019 at 04:14)</a>:</h4>
<p>Thank you, @oli, <span class="user-mention" data-user-id="116458">@Charles Lew</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>